package com.ea.demo.autogenapi.base.vo;


import org.apache.commons.lang3.StringUtils;

/**
 * Author: daiqiang
 * Date: 2019/4/2
 * Description: No Description
 */
public class DefaultResponseVo<T> extends BaseResponseVo {
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static DefaultResponseVo success(String message){
        return createDefaultResponseVo(SUCCESS,message,null);
    }

    public static <T> DefaultResponseVo<T> success(String message,T object){
        return createDefaultResponseVo(SUCCESS,message,object);
    }

    public static DefaultResponseVo fail(Integer code,String message){
        return createDefaultResponseVo(code,message,null);
    }

    public static <T> DefaultResponseVo<T> fail(Integer code,String message,T data){
        return createDefaultResponseVo(code,message,data);
    }


    public static <T> DefaultResponseVo<T> createDefaultResponseVo(Integer code,String message,T data){
        DefaultResponseVo<T> responseVo = new DefaultResponseVo<T>();
        if(code != null)
            responseVo.setCode(code);
        if(StringUtils.isNotBlank(message))
            responseVo.setMessage(message);
        if(data!=null)
            responseVo.setData(data);
        return responseVo;
    }
}
